package dao.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import dao.AttendanceDao;
import po.emp.Attendance;
import po.emp.Empoyee;

public class AttendanceDaoImpl implements AttendanceDao{
	private List<Attendance> attendances;
	public AttendanceDaoImpl() {
		attendances = new ArrayList<Attendance>();
	}
	@Override
	public boolean insert(Attendance t) {
		if(attendances.contains(t)) {
			return false;
		}
		return attendances.add(t);
	}

	@Override
	public boolean update(Attendance t) {
		int index = attendances.indexOf(t);
		if(index == -1) {
			return false;
		}else {
			attendances.set(index, t);
			return true;
		}
	}

	@Override
	public boolean delete(int id) {
		Iterator<Attendance> it = attendances.iterator();
		while(it.hasNext()) {
			Attendance e = it.next();
			if(e.getAtteId() == id) {
				it.remove();
			}
		}
		return false;
	}

	@Override
	public Attendance selectById(int id) {
		for (Attendance e : attendances) {
			if(e.getAtteId() == id) {
				return e;
			}
		}
		return null;
	}

	@Override
	public List<Attendance> selectAll() {
		List<Attendance> copy = new ArrayList<>(attendances);
		return copy;
	}
	
}
